﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Gsn.Base;
using Gsn.Common;

namespace Gsn.UI
{
    public partial class CredentialsInputForm : Form
    {
        private IController controller_;
        private bool canClose_;

        public CredentialsInputForm(IController controller)
        {
            InitializeComponent();

            this.controller_ = controller;

            this.Text = Constants.AppName + " - " + this.Text;
            this.CenterToScreen();

            if (controller_.Credentials.UserName != null)
                this.txtUserName.Text = controller_.Credentials.UserName;

            if(controller_.Credentials.Password != null)
                this.txtPassword.Text = controller_.Credentials.Password;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            controller_.SetCredentials(txtUserName.Text, txtPassword.Text);

            canClose_ = true;

            this.Close();
        }

        private void CredentialsInputForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!canClose_)
                e.Cancel = true;
        }

        private void CredentialsInputForm_Load(object sender, EventArgs e)
        {

        }
    }
}
